<?php
//$string = 'D:\ProjetosNetbeans\Dropbox\htdocs\CoreCake\app\tmp\..';
//$pattern = '/.*[.]$/';
//var_dump(preg_match($pattern, $string));exit;
?>
<style type="text/css">
    #exportTables, #createZipDiv{
        padding: 20px;
        padding-left: 260px;
        background-repeat: no-repeat;
        background-position-y: 50%;
    }
    #exportTables{
        background-image: url('<?php echo $this->Html->url('../img/installation/Places-server-database-icon.png'); ?>');
    }
    #createZipDiv{
        background-image: url('<?php echo $this->Html->url('../img/installation/Folder-Archive-zip-icon.png'); ?>');
    }
</style>
<script>
    $(function($) {
        $('body').layout('collapse', 'west');
        $('#createDump').hide();
        $('#createDumpBtn').click(function() {
            createDump();
        });
        $('#createZip').hide();
        //$('#createZipBtn').linkbutton('disable');
        $('#createZipBtn').click(function() {
            createZip();
        });
        //$('#tt').tabs('disableTab', 1);
        //$('#tt').tabs('disableTab', 3);
        checkAllCoreModules();
    });

    function checkAllCoreModules(){
        $('#modulesFormList .select input').each(function() {console.log($(this).val());
            if($(this).val() != '0' && /^Core.*$/i.test($(this).val())){
                $(this).prop('checked', !$(this).prop('checked'));
            }
        });
    }

    function createZip() {
        $('div#divLoader').window('open');
        $('#createDump').slideUp();
        $.ajax({
            type: "POST",
            url: '<?php echo $this->Html->url(array('controller' => 'CoreInstallation', 'action' => 'createZip')); ?>',
            data: $('#modulesFormList').serialize(),
            success: function(data) {
                $('#zipDiv').html(data);
                $('div#divLoader').window('close');
            }
        });
    }

    function createDump() {
        $('div#divLoader').window('open');
        $.ajax({
            type: "POST",
            url: '<?php echo $this->Html->url(array('controller' => 'CoreInstallation', 'action' => 'createDump')); ?>',
            data: $('#modulesFormList').serialize(),
            success: function(data) {
                $('#dumpDiv').html(data);
                //$('#tt').tabs('enableTab', 2);
                //$('#tt').tabs('select', 1);
                $('div#divLoader').window('close');
            }
        });
    }
</script>
<div id="tt" class="easyui-tabs" style="" data-options="fit:true" >
    <div title="<?php echo __('Tables Export'); ?>" id="exportTables">
        <form id="modulesFormList" onsubmit="return false">
            <label><?php echo __('What modules do you want to export') ?></label>
            <div style="height: 200px; overflow: auto; border: 1px #ccc solid;">
                <?php
//echo $msg;
                echo $this->CoreForm->checkboxSelectAll('CoreModules', array(
                    'label' => '',
                    'type' => 'select',
                    'multiple' => 'checkbox',
                    'options' => $modules
                ));
                ?>
            </div>
            <?php
            echo $this->Form->input('mysqlBinPath', array('placeholder' => 'C:/Program Files (x86)/Zend/MySQL55/bin/', 'required' => true, "class" => "easyui-validatebox", "value" => "C:/Program Files (x86)/Zend/MySQL55/bin/"));
            ?>
            <label for="setForReset"><?php echo __('Do not import the data');?></label>
            <?php
            echo $this->Form->checkbox('setForReset', array("value" => "1", 'label'=>"Reset Data"));
            ?>
        </form>
        <div style="text-align: center;">
            <a href="#" class="easyui-linkbutton" id="createDumpBtn" data-options="iconCls:'icon-database--arrow'"  ><?php echo __('Create Dump'); ?></a>
        </div>
        <div class="info" id="dumpDiv"></div>
    </div>
    <div title="<?php echo __('Create Zip File'); ?>" id="createZipDiv">
        <div style="text-align: center;">
            <a href="#" class="easyui-linkbutton" id="createZipBtn" data-options="iconCls:'icon-folder-zipper'"  ><?php echo __('Create Zip'); ?></a>
        </div>
        <div class="info" id="zipDiv"></div>
    </div>
</div>